package com.mys.maggie.redis.api.enums;

import org.springframework.data.redis.serializer.*;

/**
 * desc:序列化枚举
 * date:2020/10/21 19:04
 */
public enum SerializerTypeEnum {

    StringRedisSerializerEnum(1,StringRedisSerializer.class),
    Jackson2JsonRedisSerializerEnum(2, Jackson2JsonRedisSerializer.class)  ,
    GenericToStringSerializerEnum(3, GenericToStringSerializer.class),
    JdkSerializationRedisSerializerEnum(4, JdkSerializationRedisSerializer.class),
    GenericJackson2JsonRedisSerializerEnum(5, GenericJackson2JsonRedisSerializer.class );
//    OxmSerializerEnum(6, OxmSerializer.class);

    private Integer type;
    private Class serializerClass;

    SerializerTypeEnum(Integer type, Class serializerClass) {
        this.type = type;
        this.serializerClass = serializerClass;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Class getSerializerClass() {
        return serializerClass;
    }

    public void setSerializerClass(Class serializerClass) {
        this.serializerClass = serializerClass;
    }

    /**
     * 根据类型获取class
     * @param type 序列化类型
     * @return class
     */
    public static SerializerTypeEnum getSerializerEnum(Integer type){
        for ( SerializerTypeEnum enums : SerializerTypeEnum.values() ){
            if (enums.type.equals( type )){
                return enums;
            }
        }
        return SerializerTypeEnum.StringRedisSerializerEnum;
    }




}
